package com.two;

import java.util.Random;
import java.util.Scanner;

public class sushu {
    public static final int redhigh = 8;
    public static final int bulehigh = 3;

    public static void main(String[] args) {
        //人工选票
        //int []xuanhao=xuanhao();z

        //机器选票
        int []xuanhao=shanse();

        //展示选号
        System.out.print("你的号码是：");
        for (int j : xuanhao) {
            System.out.print(j+" ");
        }
        System.out.println();


        //开奖
        int []choujiang=shanse();
        //展示中奖号码
        System.out.print("中奖号码是：");
        for (int j : choujiang) {
            System.out.print(j+" ");
        }
        System.out.println();

        //核对奖票
        int money=hedui(xuanhao,choujiang);


        //显示结果
        if(money==0){
            System.out.println("谢谢惠顾");
        }
        else {
            System.out.println("恭喜你中了"+(money)+"元");
        }
    }



    private static int hedui(int[] xuanhao, int[] choujiang) {

        int red=0,bule=0,money=0;//
        for (int i = 0; i < 6; i++) {
            if(xuanhao[i]==choujiang[i]){
                red++;
            }
        }
        if(xuanhao[6]==choujiang[6]){
            bule++;
        }
        if(bule==0){
            switch (red) {
                case 4 -> money = 10;
                case 5 -> money = 20;
                case 6 -> money = 5000000;
                default -> {
                }
            }
        }
        else{
            switch (red){
                case 0->money=5;
                case 1->money=5;
                case 2->money=10;
                case 3->money=10;
                case 4->money=200;
                case 5->money=3000;
                case 6->money=1000000;
            }
        }
        return money;
    }

    private static int[] xuanhao() {//购买者选号
        int []xuanhao=new int[7] ;
        Scanner sc=new Scanner(System.in);
        int tmp=0;
        int judge=0;
        for (int i = 0; i < 6; i++) {
            System.out.println("请输入你选择的第"+(i+1)+"位红球号码");
            tmp= sc.nextInt();
            xuanhao[i]=tmp;
           do {
                judge=0;
                for (int j = 0; j <i ; j++) {
                    if (tmp == xuanhao[j]) {
                        judge= 1;
                        System.out.println("红球选择重复，请重新选择第" + (i + 1) + "位红球");
                        tmp = sc.nextInt();
                    }
                }
                if ((tmp<1||tmp>redhigh)) {
                    judge = 1;
                    System.out.println("红球范围在"+redhigh+"请重新选择第"+(i+1)+"位红球");
                    tmp= sc.nextInt();
                }
            }while(judge==1);
            xuanhao[i]=tmp;
            System.out.println("选择成功");
        }
        paixu(xuanhao);//选球红球排序后加篮球
        System.out.println("请输入你选择的蓝球号码");
        xuanhao[6]= sc.nextInt();
        do {
            judge=0;
            if ((xuanhao[6]<1||xuanhao[6]>bulehigh)) {
                judge = 1;
                System.out.println("蓝球范围在1-"+bulehigh+"之间"+"请重新选择蓝球");
                tmp= sc.nextInt();
                xuanhao[6]= tmp;
            }
        }while(judge==1);
        sc.close();
        System.out.print("你选择的号码是：");
        for (int j : xuanhao) {
            System.out.print(j+" ");
        }
        System.out.println();
        return xuanhao;
    }

    public static int []shanse(){//选出三色中奖号码数组
        int[] qiuchi=new int[redhigh];//红色球
        int[] choujiang=new  int[7];//
        for (int i = 0; i < qiuchi.length; i++) {
            qiuchi[i]=i+1;
        }
        Random ra=new Random();
        Scanner sc=new Scanner(System.in);
        int tmp=0,rd=0;
        for (int i = 0; i < 6; i++) {
            rd=ra.nextInt(qiuchi.length-i);
            choujiang[i]=qiuchi[rd];
            tmp=qiuchi[qiuchi.length-i-1];
            qiuchi[qiuchi.length-i-1]=qiuchi[rd];
            qiuchi[rd]=tmp;
        }
        paixu(choujiang);//红球排序
        choujiang[6]= ra.nextInt(bulehigh)+1;//蓝色球
        return choujiang;
    }
    public static void paixu(int []arr){//冒牌排序，要在加篮球前使用
        int left,tmp=0;
        for (int j= 0; j < arr.length-1; j++) {
            for (int i = 0; j< arr.length - i-1-1 ; i++) {
                if (arr[i] > arr[i + 1]) {
                    tmp = arr[i];
                    arr[i] = arr[i + 1];
                    arr[i + 1] = tmp;
                }
            }
        }
    }

}
